import datetime

# 全市场股票价格
def get_stock_price(database, profile_datetime):
    #
    s_update_datetime = profile_datetime.strftime('%Y-%m-%d')
    sql_str = "select max(date) from financial_data.stock_dailybar where date <=" + "'" + s_update_datetime + "'"
    max_date = database.ExecuteSQL("financial_data", sql_str)
    max_date = max_date[0][0]

    df_total_market = database.GetDataFrame("financial_data", "stock_dailybar", filter=[("date", max_date)],
                                            projection=["symbol", "close", "bclose", "total_shares", "free_float_shares"])

    return df_total_market


# get_price, 原来在 shareholder_change_plan 中使用
def get_price(database, update_datetime):
    for i in range(15):
        try_date = update_datetime - datetime.timedelta(days=i)

        df_price = database.GetDataFrame("financial_data", "stock_daily_bar", filter=[("date", try_date)],
                                         projection=["symbol", "close", "bclose", "total_shares"])
        if not df_price.empty:
            break
    # print(df_price)
    return df_price